package com.order.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    @GetMapping("/order")
    public String order(){

        System.out.println("开始下单");

        // 扣减库存
        // 基于http 协议可以使用 httpclient
        // spring 提供 restTemplate 底层实际是对 HttpClient 进行封装
        RestTemplate restTemplate = restTemplateBuilder.build();

        String url = "http://127.0.0.1:8081/repo/{1}";
        restTemplate.put(url, null, 10001);
        return "SUCCESS";
    }
}
